package cn.driver.servicecourse.mapper;

import cn.driver.common.pojo.Course;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CourseMapper {

    /**
     * 分页查询
     *
     * @param pageNo
     * @param pageSize
     * @param prm
     * @return
     */
    @Select({"<script>",
            " SELECT id, courseName, state FROM course ",
            "   <where>",
            "          <if test='prm!=null'>",
            "              concat(courseName,state) like concat('%',#{prm},'%')",
            "              ",
            "          </if>",
            "   </where>",
            " limit #{pageNo},#{pageSize}",
            "</script>"})
    List<Course> selectList(@Param("pageNo") int pageNo, @Param("pageSize") int pageSize, @Param("prm") String prm);


    /**
     * 获取总条数
     *
     * @param prm
     * @return
     */
    @Select({"<script>",
            " SELECT count(1) FROM course",
            "   <where>",
            "          <if test='prm!=null'>",
            "              concat(courseName,state) like concat('%',#{prm},'%')",
            "              ",
            "          </if>",
            "   </where>",
            "</script>"})
    int selectCount(String prm);


    @Select("SELECT id, course, state FROM course  WHERE id = #{id} ")
    Course selectOne(int id);

    /**
     * 添加
     *
     * @param course
     * @return
     */
    @Insert("INSERT INTO course (courseName)VALUES(#{courseName})")
    int add(Course course);


    @Update("UPDATE course SET id = #{id},courseName = #{courseName},state = #{state} WHERE id = #{id} ;")
    int update(Course course);

    @Delete("DELETE FROM course WHERE id = #{id};")
    int del(int id);
}
